import Vue from 'vue'
import { setToken } from '@/common/api/auth.js'

export default {
	namespaced: true,
	state: {
		showLogin: false,
	},
	mutations: {
		userInfo(state, data){
			setToken(data.token)
		},
		logout(state){
			setToken('');
		},
		setState(state, payload){
			for (let i in payload) {
				for (let j in state) {
					if (i === j) {
						state[j] = payload[i];
					}
				}
			}
		}
	},
	actions: {
		async login({commit}, data){
			commit('userInfo', data);
		},
		
		async setLogin({commit}, isShow){
			commit('setState', {showLogin: isShow});
		},
		
		async logout({commit}){
			commit('logout');
		},
	}
};
